package com.eastshop.order.adminaction;

import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.hibernate.ejb.criteria.OrderImpl;

import com.eastshop.order.service.OrderService;
import com.eastshop.order.vo.Order;
import com.eastshop.order.vo.Orderitem;
import com.eastshop.utils.PageBean;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
/**
 * 后台订单管理的Action类
 * @author admin
 *
 */
public class AdminOrderAction extends ActionSupport implements ModelDriven<Order> {
	// 模型驱动使用的对象
	private Order order = new Order();
	
	public Order getModel() {
		return order;
	}
	
	// 注入订单的Service
	private OrderService orderService;

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}
	
	// 接收page
	private int page;

	public void setPage(int page) {
		this.page = page;
	}
	
	// 查找所有的订单
	public String findAllWithPage(){
		// 分页查询所有订单的方法
		PageBean<Order> pageBean = orderService.findAllWithPage(page);
		ActionContext.getContext().getValueStack().set("pageBean", pageBean);
		return "findAllWithPage";
	}
	
	// 更新订单的状态
	public String updateState(){
		// 根据id查询订单
		order = orderService.findByOid(order.getOid());
		order.setState(2); // 等待确认收货
		orderService.update(order);
		return "updateState";
	}
	
	// 根据订单id查询订单项
	public String findOrderItemByOid(){
		List<Orderitem> list = orderService.findOrderItemByOid(order.getOid());
		ActionContext.getContext().getValueStack().set("list", list);
		return "findOrderItemByOid";
	}
}
